package com.msmall.community.common.dao.hibernate;

import java.util.List;

import com.msmall.base.dao.hibernate.BaseDaoHibernate;
import com.msmall.community.common.dao.MessageDao;
import com.msmall.community.common.model.Message;

public class MessageDaoHibernate extends BaseDaoHibernate<Message, Long> implements MessageDao{
	
	public MessageDaoHibernate(){
		super(Message.class);
	}
	
	public List<Message> getMessages(Long sender, Long receiver) throws Exception{
		String queryString = "from Message where sender=? and receiver=?";
		try{
			List list = getHibernateTemplate().find(queryString, new Object[]{sender, receiver});
			return list;
		}catch(Exception e){
			throw e;
		}
	}
	public List<Message> getMessages(Long sender, Long receiver, Integer type) throws Exception{
		String queryString = "from Message where sender=? and receiver=? and types=?";
		try{
			List list = getHibernateTemplate().find(queryString, new Object[]{sender, receiver, type});
			return list;
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * 获得用户的所有消息
	 */
	public List<Message> getMessagesByUserid(Long receiver) throws Exception{
		String queryString = "from Message where receiver=? order by createTime desc";
		try{
			List list = getHibernateTemplate().find(queryString, new Object[]{receiver});
			return list;
		}catch(Exception e){
			throw e;
		}
	}
}
